﻿@model Xms.Web.Models.SetEntityRecordStateModel
@{
    Layout = null;
}<!-- （Modal） -->
<div class="modal fade" id="setRecordStateModal" tabindex="-1" role="dialog"
     aria-labelledby="setRecordStateModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">
                    ×
                </button>
                <h4 class="modal-title" id="setRecordStateModalLabel">
                    <span class="glyphicon glyphicon-user"></span> @(Model.State == Xms.Core.RecordState.Disabled ? app.T["confirm_disabled_title"] : app.T["confirm_enabled_title"])
                </h4>
            </div>
            <div class="modal-body">
                <div class="row container-fluid">
                    <form class="form-horizontal" action="/api/data/update/state" data-jsonajax="true" method="post" asp-antiforgery="true">
                        <input type="hidden" name="entityid" value="@Model.EntityId" />
                        <input type="hidden" name="state" value="@((int)Model.State)" />
                        @{
                            int i = 0;
                            foreach (var item in Model.RecordId)
                            {
                                <input type="hidden" name="recordid[@i]" value="@item" />
                                i++;
                            }
                        }
                        <div class="form-group col-sm-12">
                            <span class="glyphicon glyphicon-warning-sign"></span>
                            <span class="text-muted">@(string.Format((Model.State == Xms.Core.RecordState.Disabled ? app.T["confirm_disabled_tip"] : app.T["confirm_enabled_tip"]), Model.RecordId.Length, ""))</span>
                        </div>
                        <div class="form-group col-sm-12">
                            @(string.Format((Model.State == Xms.Core.RecordState.Disabled ? app.T["confirm_disabled_body"] : app.T["confirm_enabled_body"]), ""))
                        </div>
                    </form>
                </div>
                <script src="/content/js/jquery.form.js?v=@app.PlatformSettings.VersionNumber"></script>
                <script>
                    var SetRecordStateModel = {
                        dialog: $('#setRecordStateModal'),
                        dialogid: 'setRecordStateModal',
                        entityid: '@Model.EntityId',
                        reload: @(Model.ReloadPage ? "true":"false"),
                        submit: function () {
                            SetRecordStateModel.dialog.find('form').submit();
                        },
                        dialog_return: function () {
                            SetRecordStateModel.dialog.modal('hide');
                        }
                    };
                    $(function () {
                        SetRecordStateModel.dialog.modal({
                            //backdrop: 'static'
                        });

                        SetRecordStateModel.dialog.on('hidden.bs.modal', function () {
                            Xms.Web.CloseDialog(SetRecordStateModel.dialogid);
                        });

                        Xms.Web.Form(SetRecordStateModel.dialog.find('form'),function (response) {
                            if (response.IsSuccess) {
                                Xms.Web.Toast(response.Content, true);
                                SetRecordStateModel.dialog_return();
                                Xms.Web.Event.publish('refresh');
                                if (SetRecordStateModel.reload) {
                                    location.reload(true);
                                }
                                return;
                            }
                            Xms.Web.Alert(false, response.Content);
                        });
                    });
                </script>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">
                    <span class="glyphicon glyphicon-remove"></span>
                    @app.T["dialog_close"]
                </button>
                <button type="button" class="btn btn-primary" onclick="SetRecordStateModel.submit()">
                    <span class="glyphicon glyphicon-ok"></span>
                    @app.T["dialog_ok"]
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->